﻿#ifndef WINDOWTOTALDATA_H
#define WINDOWTOTALDATA_H

#include <QString>
#include <QObject>
#include <QSharedPointer>
#include <QList>
#include "API_DataManager.h"
#include "BaseModule/GlobalEnums.h"
#include "PostProcessing/InfomationCurve2DBasical.h"

class QDomElement;
class QDomDocument;

class vtkActor;

namespace pst
{
    class Graph2DWindowBase;
    class Graph3DWindowBase;
    class InfomationGraph3DBasical;
}

#define WindowTotalDataInstance DataManager::WindowTotalData::getInstance()
namespace DataManager
{
    class API_DATAMANAGER WindowTotalData : public QObject
    {
        Q_OBJECT
    public:
        static WindowTotalData* getInstance();
        //清空全部数据
        void clear();

        int getLineChartWindowMaxID();
        int getPolarCoordinateGraphWindowMaxID();
        int getHeatMapWindowMaxID();
        int getSurfaceElectricFieldMapWindowMaxID();//表面分布图
        int getThreeDCloudMapWindowMaxID();//三维云图
        int getThreeDSurfacePlotWindowMaxID();//三维曲面图
        int getTableChatWindowMaxID();
        int getWindowUniversalMaxID();
        void removeWindowUniversalID(int windowUniversalID);

        int getGraph2DInformationMaxID();
        int getGraph3DInformationMaxID();

        int getThreeDCloudMapMainSettingDataMaxID();
        int getThreeDSurfacePlotMainSettingDataMaxID();
        int getSurfaceElectricFieldMapMainSettingDataMaxID();

        void addGraph2DWindow(pst::Graph2DWindowBase* window);
        void removeGraph2DWindow(pst::Graph2DWindowBase* window);
        void removeGraph2DWindowByID(int windowID);
        pst::Graph2DWindowBase* getGraph2DWindowByID(int windowID);
        pst::Graph2DWindowBase* getGraph2DWindowByUniversalID(int windowUniversalID);

        void appendInfomationCurve2DBasical(pst::Info2DPointer curveInfo);
        void removeInfomationCurve2DBasical(pst::Info2DPointer curveInfo);
        void removeInfomationCurve2DBasicalByID(int infoID);
        pst::Info2DPointer getInfomationCurve2DBasicalByID(int infoID);

        void addGraph3DWindow(pst::Graph3DWindowBase* window);
        void removeGraph3DWindow(pst::Graph3DWindowBase* window);
        void removeGraph3DWindowByID(int windowID);
        pst::Graph3DWindowBase* getGraph3DWindowByID(int windowID);
        pst::Graph3DWindowBase* getGraph3DWindowByUniversalID(int windowUniversalID);

        void appendInfomationGraph3DBasical(pst::InfomationGraph3DBasical* curveInfo);
        void removeInfomationGraph3DBasical(pst::InfomationGraph3DBasical* curveInfo);
        void removeInfomationGraph3DBasicalByID(int infoID);
        pst::InfomationGraph3DBasical* getInfomationGraph3DBasicalByID(int infoID);
        int getInfomationGraph3DBasicalIdByActor(const vtkActor* actor);

        void appendWindowUniversalID(int windowUniversalID);


        //-----------以下与项目保存相关---------------
        /// 数据写入工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* parent);
        /// 从工程文件读入数据
        bool readDataFromProjectFile(QDomNodeList* nodeList);
        //-----------以上与项目保存相关---------------


        //-----------以下与hirf外推相关--------------
        void addHirfExtrapolationCurveData(pst::Info2DPointer curveInfo, QString curveName, bool isElectricMergeData = false);
        QMultiHash<int, QString> getHirfExtrapolationCurveData();
        QMultiHash<int, QString> getHirfExpElectricMergeDataFileData();
        void removeHirfExtrapolationCurveData(int projectTreeItemID);
        void removeHirfExtrapolationCurveDataByInfo(pst::Info2DPointer curveInfo);
        //-----------以上与hirf外推相关--------------


    private:
        WindowTotalData() = default;
        ~WindowTotalData();
        void printCurrentData();

    private: 
        static WindowTotalData* _instance;

        QList<int> m_windowUniversalIDList;
        /// @brief 一个Graph2DWindowBase是一个窗口
        QList<pst::Graph2DWindowBase*> m_graph2DWindowList;
        QList<pst::Graph3DWindowBase*> m_graph3DWindowList;

        QList<pst::Info2DPointer> m_infomationCurve2DBasicalList;
        QList<pst::InfomationGraph3DBasical*> m_infomationGraph3DBasicalList;

        int m_lineChartWindowId{-1};
        int m_polarCoordinateGraphWindowId{-1};
        int m_heatMapWindowId{-1};
        int m_threeDSurfacePlotWindowID{-1};
        int m_threeDCloudMapWindowID{-1};
        int m_surfaceElectricFieldMapWindowID{-1};
        int m_tableChatWindowId{-1};
        int m_windowUniversalMaxID{-1}; // 所有窗口通用的ID，其余几个是窗口单独类别的ID

        int m_graph2DInformationMaxID{-1};
        int m_graph3DInformationMaxID{-1};

        int m_threeDCloudMapMainSettingDataID{-1};
        int m_threeDSurfacePlotMainSettingDataID{-1};
        int m_surfaceElectricFieldMapMainSettingDataID{-1};

        /// @brief <int, QString>hirf外推生成的曲线对应的项目树节点ID，hirf外推生成的曲线的名称，名称应该是两个：一个均值，一个峰值
        /// 该内容是全局性的，多个窗口，只要来源于同一个项目树节点都会修改该内容
        QMultiHash<int, QString> m_hirfExtrapolationCurvesData{};
        QMultiHash<int, QString> m_hirfExpElectricMergeDataFileData{}; // hirf外推生成的总电场数据文件路径
    };
}


#endif
